<?php
global $framework;
require_once("$framework/session.php");
require_once("$framework/debug.php");
//require_once("helpers/cart.helpers.php");

/**
 * Wizard class : parent class for any wizard.
 * @author delormef
 *
 */
class Wizard {
	/**
	 * Name of the wieard
	 * @var string.
	 */
	protected $_parent = "";
	/**
	 * Name of the manager method corresponding to the wizard execution.
	 * @var string.
	 */
	protected $_method = "";
	/**
	 * Active part of the wiozard
	 * @var anytype.
	 */
	protected $_active;
	
	/**
	 * Parameterized Constructor to set the Session option for this wizard.
	 * @param $name
	 * @param $method
	 * @return unknown_type
	 */
	public function __construct($parent="", $method=""){
		__debug(__CLASS__."::__construct() - start : parent=".$parent->getName().", method=$method",__FILE__,__LINE__);
		
		$this->_parent=$parent;
		$this->_method=$method;
		$value= Session::get($parent->getName()."_".$this->_method);
		if(empty($value)){
			Session::set($parent->getName()."_".$this->_method,"0");
		}
		$this->_active = Session::get($parent->getName()."_".$this->_method);	
		__debug(__CLASS__."::__construct() - end",__FILE__,__LINE__);
	}
	
	/**
	 * Set the active part of the wizard.
	 * @param $active
	 * @return unknown_type
	 */
	public function setActive($active){
		__debug(__CLASS__."::setActive() - start : active=$active",__FILE__,__LINE__);
		$this->_active=$active;
		Session::set($this->_parent->getName()."_".$this->_method,$active);
		__debug(__CLASS__."::setActive() - end",__FILE__,__LINE__);
	}
	
	/**
	 * Return the actived part of the wizard.
	 * @return unknown_type
	 */
	public function getActive(){
		__debug(__CLASS__."::getActive() - start",__FILE__,__LINE__);
		$this->_active = Session::get($this->_parent->getName()."_".$this->_method);
		if(empty($this->_active)){ 
			$this->_active="unknown";
		}
		__debug(__CLASS__."::getActive() - return=".$this->_active,__FILE__,__LINE__);
		return $this->_active;
	}
}
?>